import { createRouter, createWebHistory } from 'vue-router'

import routes from './routes'

const router = createRouter({
    history: createWebHistory(),
    routes
})
router.beforeEach((to, from,next) => {
    // 变量 as string
    document.title = to.meta.title as string
    // next() // 正常执行下一步解析流程

    if(to.meta.requireAuth){
        if(sessionStorage.getItem("token")){
            next()
        }else{
            if(to.path==='/login'){
                next()
            }else{
                next({
                    path:'/login'
                })
            }
        }
    }else{
        next()
    }


})

export default router